package top.songxs.gmall.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import top.songxs.gmall.feign.seckill.SeckillFeignClient;
import top.songxs.gmall.seckill.entity.SeckillGoods;

import java.util.List;

@Controller
public class SeckillController {
    @Autowired
    private SeckillFeignClient seckillFeignClient;

    @GetMapping(value = "/seckill.html")
    public String seckill(Model model) {
        List<SeckillGoods> list = seckillFeignClient.findSeckillGoodsList().getData();
        model.addAttribute("list", list);
        return "seckill/index" ;
    }

    @GetMapping(value = "/seckill/{skuId}.html")
    public String seckillGoodsDetail(@PathVariable(value = "skuId") Long skuId , Model model) {
        SeckillGoods item = seckillFeignClient.findSeckillGoodsBySkuId(skuId).getData();
        model.addAttribute("item", item);
        return "seckill/item";
    }

    @GetMapping("/seckill/queue.html")
    public String queue(@RequestParam("skuId") Long skuId,
                        @RequestParam("skuIdStr") String skuIdStr,
                        Model model){
        model.addAttribute("skuId",skuId);
        model.addAttribute("skuIdStr",skuIdStr);
        return "seckill/queue";
    }
}
